package com.atgouwu.mall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要用的数据
 */
public class OrderConfirmVo {

    //会员收获地址列表
    @Getter
    @Setter
    List<MemberAddressVo> memberAddressVos;

    //所有选中的购物项
    @Getter
    @Setter
    List<OrderItemVo> items;

    //是否有库存
    @Getter
    @Setter
    Map<Long, Boolean> stocks;

    //发票记录
    private String invoice;

    //优惠券(会员积分)
    @Getter
    @Setter
    private Integer integration;

    //防止重复提交的令牌
    @Getter
    @Setter
    private String orderToken;

    public Integer getCount() {
        Integer count = 0;
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    //订单总额
    public BigDecimal getTotal() {
        BigDecimal totalNum = BigDecimal.ZERO;
        if (items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                BigDecimal itemPrice = item.getPrice().multiply(new BigDecimal(item.getCount().toString())); //计算当前商品总价格
                totalNum = totalNum.add(itemPrice); //再计算全部商品总价格
            }
        }
        return totalNum;
    }

    //应付价格
    public BigDecimal getPayPrice() {
        return getTotal();
    }

}
